<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
   <% String path=request.getContextPath(); 
   String basePath=request.getScheme()
    + "://" + request.getServerName() + ":" + request.getServerPort() + path
    + "/"; 

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>增值税率同步</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
<script src="<%=path%>/js/json2.js" type="text/javascript"></script>
<style type="text/css">
#roleUl{list-style: none;width:93%;height:100%;text-align:left;border:0px solid red;}
#roleUl li{float: left; width:170px;border:0px solid red;line-height:24px;}
#saveAppTable tr td{border-bottom:1px solid #A4BDE3;}
</style>
<script>

$(document).ready(function() {
	queryVat(1); 
});


function warnResetPwd(obj){
	var mTr = $(obj).parent('td').parent('tr')[0];
	var uname = mTr.childNodes[2].innerHTML;
	
}

function queryVat(pageIndex){
	
	var coreRiskCode = $('#coreRiskCode').val();
	$.openLoading();
	$.ajax({
		url : '<%=path%>/systemManager/vatManager/initAllVats',
		type : 'POST',
		async : true,
		data:{'pageIndex':pageIndex,'coreRiskCode':coreRiskCode},
		dataType:'json',
		success:function(vatPage){
			$.closeLoading();
			if($.validate(vatPage))return;
			//业务处理
			if(null != vatPage){
				var buttonStr = "<a href='javascript:void(0)' onClick='singleSyncVat(this);return false'>同步</a>&nbsp;";
				var fieldNames = "deptCode@TDH,coreRiskCode,vatRate,updateTime";
				var tableContent = creatTable(fieldNames,vatPage,buttonStr);
				var tableObj = $("#vatTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(pageIndex,6,vatPage.maxPage,"58");
				var pageDIV = $("#vatPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
			}
		}
	});
	
}
//同步税率表
function vatSync(){
	$.dialog({
		type: "warn",
		content: "确定要同步税率吗？",
		onOk: function() {
	$.openLoading();
	$.ajax({
		url : "<%=path%>/systemManager/vatManager/vatSync",
		type : 'POST',
		async : true,
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if(data != null){
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    		return;
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    		return;
		    	}
				if("success"==data.result&&""!=data.message){
					$.dialog({
						type: "success",
						width:340,
						content: data.message,
						cancel:null
					});
		    	}
			}else{
				return;
			}
				
		}
	});
		}
	});
}
function singleSyncVat(vatObj){
	var delTr = $(vatObj).parent('td').parent('tr')[0];
	var deptNo = delTr.childNodes[0].innerHTML;
	var coreRiskCode = delTr.childNodes[1].innerHTML;
	$.dialog({
		type: "warn",
		content: "确定要同步核心条款代码为:"+coreRiskCode+"的税率吗？",
		onOk: function() {
	$.openLoading();
	$.ajax({
		url : "<%=path%>/systemManager/vatManager/singleSyncVat",
		type : 'POST',
		async : true,
		data:{'deptCode':deptNo,'coreRiskCode':coreRiskCode},
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if(data != null){
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    		return;
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    		return;
		    	}
				if("success"==data.result&&""!=data.message){
					$.dialog({
						type: "success",
						width:340,
						content: data.message,
						cancel:null
					});
		    	}
			}else{
				return;
			}
				
		}
	});
		}
	});
}
</script>
</head>

<body>
	<div class="current">
           <table class="current_table_1">
              <tbody><tr class="f2">
                <td><img src="./images/current_1.jpg"></td>
                  <td class="current_table_1_td">
                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                  <span style=" color:#136bab; ">系统管理
                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>增值税率同步
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody></table>
      </div>
	 	
      <table border="1" class="table_02" style="height:50px">
  		<tr height="50px">
  			
			<td colspan="2" align="center">
				模板条款代码：&nbsp;<input id="coreRiskCode" class="input_text"/>&nbsp;&nbsp;
				<input type="button" id="queryUserBtn" class="input_button_1" value="查询" onclick="queryVat(1)"/>
				<input type="button" id="vatSync"   class="input_button_2" value="vat数据同步 " onclick="vatSync()"/>
			</td>
  		</tr>
  		<tr>
  			<td valign="top">
	  			<div id="vatDIV" style="width:98%;margin:5px">
			  		<table class="table_02" id="vatTable">
			  		<thead>
		              <tr>
		                  <th style="width:25%">核心条款代码</th>
		                  <th style="width:15%">税率</th>
		                  <th style="width:25%">更新时间</th>
		                  <th style="width:25%">操作</th>
		              </tr>
		              </thead>
		              <tbody>
					  </tbody>
		            </table>
						<div id="vatPageDIV"  class="page" >
	  				 </div>
	  			</div>
  			</td>
  		</tr>
  	</table>
</body>
</html>
